package com.ruoyi.web.controller.doctor;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.doctor.domain.DoctorRegister;
import com.ruoyi.doctor.service.DoctorRegisterService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 挂号Controller
 *
 * @author ruoyi
 * @date 2022-11-14
 */
@RestController
@RequestMapping("/doctor/register")
public class DoctorRegisterController extends BaseController
{
    @Autowired
    private DoctorRegisterService doctorRegisterService;

    /**
     * 查询挂号列表
     */
    @PreAuthorize("@ss.hasPermi('doctor:register:list')")
    @GetMapping("/list")
    public TableDataInfo list(DoctorRegister doctorRegister)
    {
        startPage();
        List<DoctorRegister> list = doctorRegisterService.selectDoctorRegisterList(doctorRegister);
        return getDataTable(list);
    }

    /**
     * 导出挂号列表
     */
    @PreAuthorize("@ss.hasPermi('doctor:register:export')")
    @Log(title = "挂号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DoctorRegister doctorRegister)
    {
        List<DoctorRegister> list = doctorRegisterService.selectDoctorRegisterList(doctorRegister);
        ExcelUtil<DoctorRegister> util = new ExcelUtil<DoctorRegister>(DoctorRegister.class);
        util.exportExcel(response, list, "挂号数据");
    }

    /**
     * 获取挂号详细信息
     */
    @PreAuthorize("@ss.hasPermi('doctor:register:query')")
    @GetMapping(value = "/{registerId}")
    public AjaxResult getInfo(@PathVariable("registerId") Long registerId)
    {
        return success(doctorRegisterService.selectDoctorRegisterByRegisterId(registerId));
    }

    /**
     * 新增挂号
     */
    @PreAuthorize("@ss.hasPermi('doctor:register:add')")
    @Log(title = "挂号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DoctorRegister doctorRegister)
    {
        return toAjax(doctorRegisterService.insertDoctorRegister(doctorRegister));
    }

    /**
     * 修改挂号
     */
    @PreAuthorize("@ss.hasPermi('doctor:register:edit')")
    @Log(title = "挂号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DoctorRegister doctorRegister)
    {
        return toAjax(doctorRegisterService.updateDoctorRegister(doctorRegister));
    }

    /**
     * 删除挂号
     */
    @PreAuthorize("@ss.hasPermi('doctor:register:remove')")
    @Log(title = "挂号", businessType = BusinessType.DELETE)
    @DeleteMapping("/{registerIds}")
    public AjaxResult remove(@PathVariable Long[] registerIds)
    {
        return toAjax(doctorRegisterService.deleteDoctorRegisterByRegisterIds(registerIds));
    }

    /**
     * 根据状态查询挂号
     * @param registerStatus
     * @return
     */
    @GetMapping("/getListByStauts/{registerStatus}")
    public AjaxResult getListByStauts(@PathVariable Integer registerStatus){
        return AjaxResult.success(doctorRegisterService.selectListByRegisterStatus(registerStatus));
    }

    /**
     * 接诊
     * @param registerId
     * @return
     */
    @PutMapping("/treat/{registerId}")
    public AjaxResult treatPatient(@PathVariable Long registerId){
        DoctorRegister doctorRegister = new DoctorRegister();
        //设置主键
        doctorRegister.setRegisterId(registerId);
        //设置接诊医生
        doctorRegister.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(doctorRegisterService.updateTreatPatient(doctorRegister));
    }
}

